#ifndef KNN_H
#define KNN_H

#include "logger.h"

#include<iostream>
#include<map>
#include<vector>
#include<stdio.h>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<fstream>

using namespace std;

typedef char tLabel;
typedef double tData;
typedef pair<int,double>  PAIR;
const int colLen = 2;
const int rowLen = 12;


class KNN
{
public:
    KNN(int k);
    bool init();
    //calculate all the distance between test data and each training data
    void get_all_distance();
    //check which label the test data belongs to to classify the test data
    void get_max_freq_label();
    struct CmpByValue
    {
        bool operator() (const PAIR& lhs,const PAIR& rhs)
        {
            return lhs.second < rhs.second;
        }
    };

private:
    //calculate the distance between test data and dataSet[i]
    inline double get_distance(tData *d1,tData *d2);

private:
    KNN();
    tData dataSet[rowLen][colLen];
    tLabel labels[rowLen];
    tData testData[colLen];
    int k;
    map<int,double> map_index_dis;
    map<tLabel,int> map_label_freq;
};

#endif // KNN_H
